#ifndef QUIXML_H
#define QUIXML_H

#include "shared_global.h"

#include "../../include/qcommonstruct.h"

#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QList>
#include <QMap>

#include <QVariant>

class SHAREDSHARED_EXPORT XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r)=0;
    virtual     void write(QXmlStreamWriter &w)=0;

    QVariant    value();
    void        setValue(QVariant value);
protected:
    QVariant    m_value;
};

class SHAREDSHARED_EXPORT XMLStringValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
};

class SHAREDSHARED_EXPORT XMLSizeValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);

protected:
    int         readSubValue(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLRectValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);

protected:
    int         readSubValue(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLPaddingValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);

protected:
    int         readSubValue(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLIntValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
};

class SHAREDSHARED_EXPORT XMLFloatValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
};

class SHAREDSHARED_EXPORT XMLBoolValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
};

class SHAREDSHARED_EXPORT XMLFontValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    QString     readSubValue(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLComboItemsValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    tagComboItem readSubItem(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLTimeValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    int         readSubItem(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLDateValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    int         readSubItem(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLDateTimeValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    int         readSubItem(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLColorValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    int         readSubItem(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLBorderValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    int         readSubItem(QXmlStreamReader &r);
    QString     readText(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLImageValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    int         readInt(QXmlStreamReader &r);
    QString     readText(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLMemeryDataValue: public XMLValue
{
public:
    virtual     void read(QXmlStreamReader &r);
    virtual     void write(QXmlStreamWriter &w);
protected:
    tagMemeryValueInfo     readSubItem(QXmlStreamReader &r);
};

class SHAREDSHARED_EXPORT XMLProperty
{
public:
    XMLProperty();

    void        read(QXmlStreamReader &r);
    void        write(QXmlStreamWriter &w);

    QVariant    value();
    void        setValue(QVariant value);

    QString     propertyName();
    void        setPropertyName(const QString& name);

    void        setType(const QString &type);
    QString     type();
protected:
    XMLValue    *createValue(const QString type);
protected:
    XMLValue    *m_value;
    QString     m_type;
    QString     m_propertyName;
};

class SHAREDSHARED_EXPORT XMLWidget
{
public:
    XMLWidget(XMLWidget* parent=0);
    ~XMLWidget();
    void        read(QXmlStreamReader &r);
    void        write(QXmlStreamWriter &w);

    void        setAttribute(const QString &key,const QString &value);
    QString     attribute(const QString &key,const QString &def=QString());

    XMLProperty *addProperty();
    QList<XMLWidget*>   children();
    QList<XMLProperty*> propertys();
protected:
    QList<XMLProperty*>     m_propertys;
    QMap<QString,QString>   m_attributes;

    QList<XMLWidget*>       m_children;
    XMLWidget*              m_parent;
};

#endif // QUIXML_H
